package ypmits.bitmap.layers {
	import ypmits.bitmap.vo.BitmapLayersVO;
	import flash.display.Bitmap;
	import flash.display.LineScaleMode;
	import flash.display.Shape;
	import flash.display.Sprite;
	import flash.geom.ColorTransform;
	import flash.geom.Rectangle;

	/**
	 * @author Dave Lenz
	 */
	public class BitmapParticle extends Sprite {
		public var MIN_SCALE : Number = .3;
		public var MAX_SCALE : Number = 1;
		public var MOUSE_DISTANCE : int = 30;
		private var _oldscale : Number = 1;
		private var bmVO : BitmapLayersVO;
		private var bm : Bitmap;
		private var c : Shape;

		public function BitmapParticle( bmVO : BitmapLayersVO ) 
		{
			this.bmVO = bmVO;
			
			bm = new Bitmap( );
			addChild( bm );
			
			c = new Shape( );
			addChild( c );
		}
		
		
		public function setBitmap(b : Bitmap) : void
		{
			var r : Rectangle = c.getBounds(this);
			b.x = r.x;
			b.y = r.y;
			addChildAt( b, 0 );
			
			this.cacheAsBitmap = true;
		}

		
		public function shapeShift( num : Number ) : void
		{
			if( num > _oldscale ) 
			{
				this.scaleX = this.scaleY = num;
			}
		}
//
//		
//		private function setScale( scale : Number ) : void
//		{
//			_oldscale = scale;
//		}

		
		public function drawCircle( _x : Number = 0, _y : Number = 0, brightness : Number = 0, color : uint = 0x000000 ) : void 
		{
			c.graphics.clear( );
			c.graphics.lineStyle(1, 0xFF9900, 1, false, LineScaleMode.NONE );
			c.graphics.beginFill( color, bmVO.alpha );
			c.graphics.drawCircle( _x, _y, (1 - brightness) * bmVO.maxradius );
			c.graphics.endFill( );
		}

		
		public function activate() : void 
		{
			var clr : ColorTransform = new ColorTransform( );
			clr.color = 0xFF9900;
			
			transform.colorTransform = clr;
		}

		
		public function deactivate() : void 
		{
			transform.colorTransform = null;
		}
	}
}
